unit uMainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, ComCtrls, RzEdit, StdCtrls, RzTray, Menus, ActnList;

type
  TForm1 = class(TForm)
    Button1: TButton;
    btnSetup: TButton;
    RzHotKeyEdit1: TRzHotKeyEdit;
    RzHotKeyEdit2: TRzHotKeyEdit;
    procedure actSetupExecute(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FKey: LongInt;
    procedure WMHotKey(var Message: TWMHotKey); message WM_HOTKey;
  end;

var
  Form1: TForm1;

implementation

uses uSetupForm;

{$R *.dfm}

procedure TForm1.actSetupExecute(Sender: TObject);
//var
//  frmHotKeyDisplay: TfrmHotKeyDisplay;
begin
  if not Assigned(frmHotKeyDisplay) then
    frmHotKeyDisplay := TfrmHotKeyDisplay.Create(Application);

  frmHotKeyDisplay.Show;
end;

{
************************************ TForm1 ************************************
}

procedure TForm1.Button1Click(Sender: TObject);
begin
  RzHotKeyEdit2.HotKey := FKey; //RzHotKeyEdit1.HotKey;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FKey := RzHotKeyEdit1.HotKey;

  caption := IntToStr(FKey);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Handle, GlobalAddAtom('hotkey'), MOD_WIN, VK_F12);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnregisterHotKey(Handle, GlobalAddAtom('hotkey'));
  GlobalDeleteAtom(GlobalFindAtom('hotkey'));
end;

procedure TForm1.WMHotKey(var Message: TWMHotKey);
begin
  if Message.HotKey = GlobalFindAtom('HotKey') then
  begin
    ShellExecute(Handle, 'open', pchar('mstsc.exe'), '/v 10.204.9.196', ' /console ', SW_SHOW);
  end;
end;

{ TForm1 }

end.

